#pragma once
#include "Actor.h"
#include "Texture.h"

namespace mini
{
	class CRenderToTexture : public CActor
	{
	public:
		CRenderToTexture(INT32 width, INT32 height);
		virtual ~CRenderToTexture();
		bool createBuffer(UINT32 format, UINT bindInfo, UINT32 nTextureFormat);
		void beginRender( const CPoint4F& clearColor, DeviceContext* pConetext);
		void endRender(DeviceContext* pConetext);
		CTexture* getRenderTexture();
		bool  saveToFile(const std::string szFile, UINT32 nFormat = D3DX11_IFF_PNG);
		void setSampler(ID3D11SamplerState* pSampler);
		void createViewport();
		void applyViewport(DeviceContext* pConetext, int nIndex = 1);
		CMatrix& getProjectMatrix();
		CMatrix& getOrthoMatrix();
		ID3D11RenderTargetView* getRenderTargetView();

	private:
		INT32 mWidth = 0;
		INT32 mHeight = 0;
//		DeviceContext* mpDeviceContext = nullptr;
		CTexture* mpTexuture = nullptr;
		ID3D11Texture2D* mpDepthStencilBuffer = nullptr;
		ID3D11DepthStencilView* mpDepthStencilView = nullptr;

		CMatrix mProjectMatrix;
		CMatrix mOrthoMatrix;
		D3D11_VIEWPORT m_viewport;
	};
}
